import { DomUtils } from '../utils/DomUtils';

/**
 * ### 脚本之家网页美化
 * 
 * 测试网页：
 * - https://www.jb51.net/
 * - https://www.jb51.net/python/337068ysr.htm
 */
export class Jb51 {

    static hostname = 'www.jb51.net';

    main(pathname)  {
        if (pathname === '/') {
            this.handleHome()
        } else {
            this.handleArticle();
        }
    }

    /**
     * 处理文章页面
     */
    handleArticle() {
        DomUtils.hide([
            '#topbar',
            '#header',
            '#nav',
            '#submenu',
            '#container > div:first-child',
            ...document.querySelectorAll('#content img'),
            document.querySelector('#content').nextElementSibling,
            document.querySelector('#content').nextElementSibling.nextElementSibling,
            document.querySelector('#content').nextElementSibling.nextElementSibling.nextElementSibling,
            '.main-right',
            document.querySelector('.breadcrumb').parentElement,
            '#comments',
            '#footer'
        ]);
        DomUtils.setCss('#main', { width: '850px' });
        DomUtils.setCss('#wrapper', { padding: '20px 0', background: 'none' });
        DomUtils.setCss('.main-left', { paddingRight: 0 });
        DomUtils.setCss('#CatelogList', { padding: '20px', backgroundColor: '#fff' });
        DomUtils.setBackground();
    }

    /**
     * 处理网站首页
     */
    handleHome() {
        DomUtils.hide([
            // 网站Logo右边的两个图片广告
            '.logom', '.logor',
            // 页面中的横条型广告
            document.querySelector('#container').children[2],
            ...document.querySelectorAll('#container > .main:last-child .mainlr'),
            ...document.querySelectorAll('.topimg'),
            ...document.querySelectorAll('.dxy1200'),
        ]);
    }
}